package com.goldsign.pay.provider.msg.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.goldsign.pay.provider.msg.config.AppConfig;
import com.goldsign.pay.provider.msg.rabbit.producer.RbtProducer;





/**使用@RefreshScope注解的类，会在接到SpringCloud配置中心配置刷新的时候，自动将新的配置更新到该类对应的字段中*/
@RefreshScope 
@RestController
@RequestMapping("sms")
public class MsgController{
    private static final Logger LOGGER = LoggerFactory.getLogger(MsgController.class);

//    @Value("${param.mq.default-queue}")
//    String default_queue;
    
    @Autowired
    AppConfig config;
    
    @Autowired
    private RbtProducer producer;
    
    @RequestMapping(method={RequestMethod.GET,RequestMethod.POST}  ,value = "/")
    public void send(@RequestParam String content) {
    	LOGGER.info("send msg:{}  to:{}" , content, config.getDefaultQueue());
    	producer.send(config.getDefaultQueue(), content);
    }
    
    @RequestMapping(method={RequestMethod.GET,RequestMethod.POST}  ,value = "/2")
    public void sendMsgTopic(@RequestParam String content) {
    	LOGGER.info("send msg:{}  to:{}" , content, config.getDefaultQueue());
//    	producer.send(config.getDefaultExchange(),config.getDefaultQueue(), content);
//    	producer.send("dev.topicExchange","dev.topic.A", "A:" + content);
    	producer.send("dev.topicExchange","dev.topic.B", "B" + content);
    }

    @RequestMapping(method={RequestMethod.GET,RequestMethod.POST}  ,value = "/3")
    public void sendMsgFanout(@RequestParam String content) {
    	LOGGER.info("send msg:{}  to:{}" , content, config.getDefaultQueue());
//    	producer.send("dev.fanoutExchange","dev.fanout.A", "FanA:" + content);
//    	producer.send("dev.fanoutExchange","dev.fanout.B", "FanB:" + content);
//    	producer.send("dev.fanoutExchange","dev.fanout.C", "FanC:" + content);
//    	producer.send("dev.fanoutExchange", null , "@Fan Null:" + content);
    	 
    	producer.send("dev.fanoutExchange" ,"dev.topic.B", "Bxxx" + content);
    }
    
    @RequestMapping(method={RequestMethod.GET,RequestMethod.POST}  ,value = "/4")
    public void sendMsgShop(@RequestParam String content) {
    	LOGGER.info("send msg:{}  to:{}" , content, config.getDefaultQueue());
    	producer.send("dev.topicExchange.shop" ,"dev.order.store.123456", "test order" + content);
    }
}